<template>
	<view>
		<view class="relative">
			<image src="https://gsconline-1251028293.cos.ap-guangzhou.myqcloud.com/images/2020/05/19/image_158987206310210097.png"
			 mode="widthFix" class="w100"></image>
			<view class="absolute statistics_view">
				<cu-custom :isBack="true" style="color: #FFF !important;">
					<block slot="backText"></block>
					<block slot="content"><text>{{title}}</text></block>
				</cu-custom>
				<view class=" text-white text-center">
					<view class="text-xxxl margin-top" v-if="t=='frozen_money2'">
						{{member?member.account.frozen_money2:0}}
					</view>
					<view class="text-xxxl margin-top" v-else>
						{{member?member.account.frozen_money:0}}
					</view>
					<view class="cu-btn line-blue margin-top round" v-if="t!='frozen_money2'" @tap="goPage('/pages/member/withdraw/apply2')">提现</view>
				</view>
			</view>
		</view>

		<view class="relative w100">
			<view class="absolute objlist w100 padding-lr">
				<view class="bg-white radius margin-top">
					<!-- <scroll-view scroll-x class="bg-white nav solid-bottom">
						<view class="flex text-center">
							<view class="cu-item flex-sub text-cut" :class="index==TabCur?'text-orange cur':''" v-for="(item,index) in tabs"
							 :key="index" @tap="tabSelect" :data-id="index">
								{{item.name}}({{item.count}})
							</view>
						</view>
					</scroll-view> -->

					<view class="cu-list menu-avatar">
						<view class="cu-item" v-for="(item,index) in list" :key="index">
							<view class="cu-avatar lg bg-white round">
								<image v-if="item.fromMember && item.fromMember.head_portrait" :src="item.fromMember.head_portrait" mode="aspectFill"></image>
								<image v-else src="https://gsconline-1251028293.cos.ap-guangzhou.myqcloud.com/images/2020/05/19/image_158987220710257979.png"
								 mode="aspectFill"></image>
							</view>
							<view class="content">
								<view v-if="item.fromMember"><text class="text-bold">{{item.fromMember.nickname}}({{item.fromMember.id}})</text><text
									 class="cu-tag sm bg-orange round">{{item.fromMember.level.name}}</text></view>
									 <text v-if="item.frozen == 1" class="cu-tag">待返</text>
								<view class="text-gray text-left">{{$common.timeFormat(item.created_at,'YYYY-MM-DD h:m:s')}}</view>
							</view>
							<view class="action" style="min-width: 200rpx;">
								<view class="text-orange text-sm">{{item.remark}}</view>
								<view class="text-orange">{{(item.num)}}</view>
							</view>
						</view>
					</view>
					<view class="cu-load margin-center" :class="loading?'loading':'over'"></view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import Cubar from '@/components/default/Cubar.vue'
	import {
		mapState
	} from 'vuex'
	export default {
		components: {
			Cubar
		},
		computed: mapState(['forcedLogin', 'hasLogin', 'channelLogin']),
		data() {
			return {
				statistics: null,
				TabCur: 0,
				member: null,
				list: [],
				page: 1,
				hasMore: true,
				loading: false,

				t: 'frozen_money',
				title: '本金余额明细'
			}
		},
		onLoad(options) {
			if (options.t) {
				this.t = options.t
				this.title = '金币明细'
			}
		},
		onShow() {
			if (this.$common.loginAuth(true)) {
				this.$common.getMember().then((member) => {
					this.member = member
					this.getList()
				})
			}
		},
		methods: {
			tabSelect(e) {
				if (this.TabCur != e.currentTarget.dataset.id) {
					this.TabCur = parseInt(e.currentTarget.dataset.id)
					this.getList(this.TabCur)
				}
			},
			getInfo() {
				this.$http
					.get('integral_info', {})
					.then((response) => {
						this.statistics = response.data.data
						this.$common.setCache('credit_statictics', this.statistics, 10 * 60)

						this.tabs[0].count = this.statistics.credits_declaration
						this.tabs[1].count = this.statistics.credits_shop
						if (this.tabs[2]) {
							this.tabs[2].count = this.statistics.credits_company
						}
						uni.hideLoading()
						uni.stopPullDownRefresh()
					})
					.catch((response) => {
						console.log(response)
					})
			},
			getList() {
				if (this.hasMore) {
					this.loading = true
					this.$http
						.get('integral_details', {
							page: this.page,
							credit_type: this.t
							// group_type: obj.group_type
						})
						.then((response) => {
							let list = this.list
							if (response.data.data.length > 0) {
								list = list.concat(response.data.data)
							} else {
								this.hasMore = false
							}
							this.list = list
							this.loading = false
							this.page += 1
							uni.stopPullDownRefresh()
						})
						.catch((response) => {
							console.log(response)
							this.loading = false
						})
				}
			},
			showModal(e) {
				this.modalName = e.currentTarget.dataset.target
			},
			hideModal(e) {
				this.modalName = null
			},
		},
		onReachBottom() {
			this.getList()
		},
		onPullDownRefresh() {
			this.list = []
			this.hasMore = true
			this.page = 1
			this.loading = false
			this.getList()
		},
	}
</script>

<style>
	.relative {
		position: relative;
	}

	.absolute {
		position: absolute;
	}

	.statistics_view {
		left: 0;
		top: 0;
		width: 100%;
	}

	.text-xxxl {
		font-size: 80rpx;
	}

	.btnr {
		border-radius: 40rpx 0 0 40rpx;
		padding: 0 40rpx;
		height: 50rpx;
	}

	.m-title {
		font-size: 32rpx !important;
		position: relative;
		display: block;
	}

	.m-title::after {
		content: "";
		left: 0;
		position: absolute;
		width: 70rpx;
		height: 4rpx;
		bottom: 0;
		background-color: #ffb03a;
		z-index: 0;
	}

	.mfixed {
		width: 100%;
		position: fixed;
		top: 0;
	}

	.objlist {
		top: -0rpx;
	}

	.goods-thumb {
		width: 180rpx;
		height: 180rpx;
		min-width: 180rpx;
	}

	.goods-thumb image {
		width: 100%;
		height: 100%;
	}
</style>
